<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<%@ include file="/common/plateform/include/common-base.jsp"%>

	<title>资源管理</title>
	<!-- Tell the browser to be responsive to screen width -->
	<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
</head>
<body class="hold-transition ${sysColor} sidebar-mini">
<div class="wrapper">

	<!-- top start -->
	<%@include file="/common/plateform/top.jsp" %>
	<!-- top end -->
	<!-- left start -->
	<%@include file="/common/plateform/left.jsp" %>
	<!-- left end-->

	<div class="content-wrapper">
		<!--
           <ol class="breadcrumb bgblue">
               <li>
                   <span class="label label-danger font14" >机构与用户管理 / 资源管理</span>
               </li>
           </ol>
       -->
		<!-- Main start -->

		<section class="content">
			<div class="row">
				<div class="col-xs-12">
					<div class="box box-success">

						<div class="box-header with-border">
							<h3 class="box-title"><i class="fa fa-user"></i>  资源管理
								<button class="btn btn-success" type="button" onclick="toAdd();">增加子节点</button>
								<button class="btn btn-danger" type="button" onclick="del();">删除</button>
								<button class="btn btn-warning" type="button" onclick="toEdit();">修改</button>
								<button class="btn btn-info" type="button" onclick="refresh();">刷新</button>
							</h3>
							<div class="box-tools pull-right">
								<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
								</button>
								<button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
							</div>
						</div>


						<div class="box-body">
							<table id="example" class="table tableEdit table-bordered table-hover" >
								<thead>
								<tr>
									<th>资源名称</th>
									<th>英文全称/中文全称/权限地址</th>
									<th>类型</th>
									<th>状态</th>
								</tr>
								</thead>
								<tbody id="myList"></tbody>
							</table>
						</div>



					</div>
				</div>
			</div>
		</section>

		<div class="modal fade" id="my_edit_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
						<h4 class="modal-title"><font color="red">资源信息</font>&nbsp;</h4>
					</div>
					<div class="modal-body">
						<form class="form-horizontal" role="form" id="actSaveForm">
							<input type="hidden" name="formToken" id="formToken" value="${formToken}"/>
							<input type="hidden" name="doCode" value="saveAct"/>
							<input type="hidden" name="actId" id="data-actId" class="clean" value=""/>
							<input type="hidden" name="fatherId" id="data-fatherId" value="0"/>

							<div class="box-body" id="orgFormData">
								<div class="form-group">
									<label class="col-sm-4 control-label">资源标识</label>
									<div class="col-sm-6">
										<input type="text" class="form-control clean" id="data_actEname" data-name="actEname"  name="actEname" required placeholder="必填项">
									</div>
								</div>
								<div class="form-group">
									<label  class="col-sm-4 control-label" >资源名称</label>
									<div class="col-sm-6">
										<input type="text" class="form-control clean" data-name="actCname"   name="actCname" required placeholder="必填项">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-4 control-label">资源类型</label>
									<div class="col-sm-6">
										<input type="radio" name="actType" id="actType_menu" value="menu" onclick="uPssOrN('N')" />菜单
										<input type="radio" name="actType"  id="actType_action" value="action" onclick="uPssOrN('Y')"/>action
									</div>
								</div>
								<div class="form-group isupdPass">
									<label class="col-sm-4 control-label">权限地址</label>
									<div class="col-sm-6">
										<input type="text" class="form-control" id="data_actUrl"  name="actUrl" placeholder="">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-4 control-label">状态</label>
									<div class="col-sm-6">
										<input type="radio" name="actStatus" id="actStatus_1" value="1" />启用
										<input type="radio" name="actStatus"  id="actStatus_0" value="0" />停用
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-4 control-label">排序值</label>
									<div class="col-sm-6">
										<input type="text" class="form-control  clean" data-name="orderNum"  name="orderNum" >
									</div>
								</div>
							</div>
							<div class="box-footer">
								<input type="reset" name="reset" style="display: none;" />
								<button type="button" class="btn btn-primary pull-left" onclick="cannel('my_edit_modal');">取消</button>
								<button type="button" class="btn btn-primary pull-right" onclick="saveItem('actSaveForm');">提 交</button>
							</div>
						</form>
					</div>
				</div>
				<!-- /.modal-content -->
			</div>
		</div>

		<script type="text/template" id="dataList">
			<? for ( var i = 0; i < rows.length; i++) {?>
			<tr id=<?=rows[i].uctAct.actId?>  fatherId=<?=rows[i].uctAct.fatherId?>>
				<th style="display:none;"><?=rows[i].uctAct.actId?></th>
				<th style="display:none;"><?=rows[i].uctAct.actCname?></th>
				<th style="display:none;"><?=rows[i].uctAct.fatherId?></th>
				<td class="textLeft" id="css_<?=rows[i].uctAct.actId?>"> <?if(rows[i].uctAct.subCount>0||"0"==rows[i].uctAct.fatherId){?>
					<i class="fa fa-folder fa-cyellow"  onclick="getChildActsData('<?=rows[i].uctAct.fatherId?>','<?=rows[i].uctAct.actId?>','<?=rows[i].uctAct.fullEname?>',this);"></i>&nbsp;<?=rows[i].uctAct.actCname?>
					<?} else{?>
					<i class="fa fa-file-text fa-cyellow"></i>&nbsp;<?=rows[i].uctAct.actCname?>
					<?}?>
				</td>
				<td class="textLeft">
					<?=rows[i].uctAct.fullEname?>
					<span class="fx12">[<?=rows[i].uctAct.fullCname?>]</span>
					<?if(!strUtil.isNull(rows[i].uctAct.actUrl)){?>
					<br/><span class="fx8"><?=rows[i].uctAct.orderNum?>.<?=rows[i].uctAct.actUrl?></span>
					<?}?>
				</td>
				<td><? if("menu"==rows[i].uctAct.actType){?>菜单<?}else{?>action<?}?></td>
				<td><? if("0"==rows[i].uctAct.actStatus){?>停用<?}else{?>启用<?}?></td>
			</tr>
			<?}?>
		</script>
		<script>
            var clickMenu= 'menu-list';
            var id;
            var orgEname;
            var sysFlag='${loginUser.sysFlag}';
            $(function () {
				if(sysFlag!='1'){
                    orgEname='${loginUser.orgEname}';
				}

                getTableData();
                $('#example tbody').on('click','tr', function (e) {
                    if ( $(this).hasClass('selected') ) {
                        //$(this).removeClass('selected');
                    } else {
                        $('tr.selected').removeClass('selected');
                        $(this).addClass('selected');
                    }
                    id = $('tr.selected th').eq(0).html();
                } );
            });
            //设置模态框隐藏事件钩子
            $( '#my_modal' ).on( 'hide.bs.modal' ,function(e){
                cleanData('userFormData');
            });


            function cleanData(id){
                $(':input','#'+id)
                    .not(':button, :submit, :reset, :hidden')
                    .val('')
                    .removeAttr('selected');
            }

            function getTableData(){
                deleteAllRow('example');

                $.ajax({type:'get',
                    url:common_list_url,
                    // data:{'id':'0','doCode':'treeAct'},
                    data:{'pageName':'uct-act-list','formName':'searchForm','uctAct.w_actEname':orgEname,'uctAct.fatherId':'0'},
                    dataType:'json',
                    success: function(myData){

                        var myDatas = new Object();
                        myDatas.rows = myData;
                        console.log(myDatas);
                        console.log(myData);
                        // var data = baidu.template('dataList',eval(myDatas));
                        var data = baidu.template('dataList',eval(myData));
                        $("#myList").html(data);
                    }
                });
            }

            function deleteAllRow(tableId){
                var tb = document.getElementById(tableId);
                if(tb){
                    var rowNum=tb.rows.length;
                    for (i=1;i<rowNum;i++){
                        tb.deleteRow(i);
                        rowNum=rowNum-1;
                        i=i-1;
                    }
                }
            }
            function toAdd(){
                $("#if-sysFlag").show();
                $("input[type=reset]").trigger("click");
                $('#my_edit_modal').modal('show');
                $('#data_actUrl').attr("required","false");
                $('.isupdPass').hide();
                $("#data-fatherId").val(id);
                initRadio("actType","menu");
                initRadio("actStatus","1");
                $("#data_actEname").attr("readonly",false);
            }

            function toEdit(){
                //$('#actSaveForm').reset();
                if(id=="undefined" || id =="" || id == null){
                    alert("请先选中一条数据！");
                    return;
                }else{
                    $.ajax({ type:'get', url:common_info_url,dataType:'json',
                        data:{'actId':id,'doCode':'actInfo'},
                        success: function(myData){
                            console.log(myData);
                            getObjInfo(myData);
                        }
                    });
                }
                //$('#my_modal').modal('show');
            }

            function getObjInfo(myData){
                mytools.cleanData("#actSaveForm");
                FormUtil.loadView("", myData);
                $('#my_edit_modal').modal('show');
                if("menu"==myData.actType){
                    $('#data_actUrl').attr("required","false");
                    $('.isupdPass').hide();
                }else{
                    $('#data_actUrl').attr("required","true");
                    $('.isupdPass').show();
                }
                $("#data_actEname").attr("readonly",true);
                $('#data_actUrl').val(myData.actUrl);
                $("#data-fatherId").val(myData.fatherId);
                $("#data-actId").val(myData.actId);
                initRadio("actType",myData.actType);
                initRadio("actStatus",myData.actStatus);
            }

            function saveItem(formId){
                setToken();
                $.ajax({ type:'post', url:common_submit_url,dataType:'json',
                    data:$("#"+formId).serialize(),
                    success: function(myData){
                        setToken();
                        layer.alert(myData.msg, {icon: 1,closeBtn: 0,offset: '220px'});
                        if(myData.flag=='T'){
                            getTableData();
                            $('#my_edit_modal').modal('hide');
                        }
                    }
                });
            }

            function del(){
                if(id =="undefined"){
                    alert("请先选中一条数据！");
                    return;
                }else{
                    $.ajax({ type:'post',url:common_submit_url,dataType:'json', data:{'id':id,'doCode':'delAct'},
                        success: function(myData){
                            layer.alert(myData.msg, { closeBtn: 0 });
                            if(myData.flag=='T'){refresh();}
                        }
                    });
                }
            }

            function cannel(modalId){
                $("input[type=reset]").trigger("click");
                $('#'+modalId).modal('hide');
            }


            function refresh(){
                getTableData();
            }

            function getChildActsData(fatherId,actId,treeLevel,obj){
                // alert(fatherId+"------"+actId+"------"+treeLevel+"------"+obj)
                var count =0;
                var ss = treeLevel.split("/");
                count = ss.length-1;
                $.ajax({ type:'get',url:common_list_url,
                    // data:{'id':actId,'doCode':'treeAct','actId':actId},
                    data:{'pageName':'uct-act-list','formName':'searchForm','uctAct.w_fatherId':actId},
                    dataType:'json',
                    success: function(myData){
                        var myDatas = new Object();
                        console.log(myData);
                        myDatas.rows = myData;
                        // var data = baidu.template('dataList',myDatas);
                        var data = baidu.template('dataList',myData);
                        if($(obj).hasClass("fa-folder-open")){ $(obj).attr("class","fa fa-folder"); delActsChiled(actId);
                        }else{
                            $(obj).attr("class","fa fa-folder-open  fa-cyellow");
                            $("#"+actId).after(data);
                            $("[fatherid='"+actId+"']").each(function(i){
                                var thisObj = $(this);
                                var pd = "10px 20px 10px ";
                                var num = pd+(count*20)+"px";
                                $(thisObj).find("td").eq(0).css("padding",num);
                            });
                        }
                    }
                });
            }
            function delActsChiled(id){
                $("[fatherid='"+id+"']").each(function(i){
                    var thisObj = $(this);
                    $(thisObj).remove();
                    var id = thisObj.attr("id");
                    delActsChiled(id);
                });
            }

            function uPssOrN(flag){
                if(flag == 'Y'){
                    $('#data_actUrl').attr("required","true");
                    $('.isupdPass').show();
                }else if(flag == 'N'){
                    $('#data_actUrl').attr("required","false");
                    $('.isupdPass').hide();
                }
            }
            function initRadio(elemname,selVl){
                var myobj=document.getElementsByName(elemname);
                if(myobj==null)return;
                for ( var i = 0; i < myobj.length; i++) {
                    if (myobj[i].value == selVl) {
                        myobj[i].checked = "true";
                    }
                }
            }
            function setToken(){
                $.ajax({ type:'get',url:'${ctx}/sendPage/token?token=true',dataType:'text',async:false,
                    success: function(myData){ $('#formToken').val(myData);	}
                });
            }
		</script>


		<!-- Main end -->
	</div>
	<%@include file="/common/plateform/foot.jsp" %>


</body>




</html>


